package com.duanjw.springboot.profiles.config;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * 测试环境激活的配置
 * InitializingBean接口：当bean被容器初始化完成后会调用实现InitializingBean接口类的afterPropertiesSet()方法
 * 1. @Configuration：被此注解标识的类会放到容器中
 * 2. @Profile：当激活的配置环境是dev时，此类生效
 *
 * @author duanjw
 */
@Configuration
@Profile("dev")
public class DevConfiguration implements InitializingBean {

    /**
     * 注入value属性的值
     */
    @Value("${my.value}")
    private String value;

    /**
     * bean初始化完成后会调用此方法
     *
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.err.println("DevConfiguration value 是：" + value);
    }
}
